﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Online_Model;
namespace Online_DAL
{
    public class Onlien_User
    {
        /// <summary>
        /// 连接数据库
        /// </summary>
        string constring = ConfigurationManager.ConnectionStrings["mysql"].ToString();
        /// <summary>
        /// 用户权限登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public List<Users> GetUserList(string name ,string pwd)
        {
            try
            {
                List<Users> list = new List<Users>();
                string StrSql = "SELECT users.*,ROLE.* FROM users JOIN ROLE ON users.Roleid=ROLE.Roleid WHERE users.Uname='" + name + "' AND users.Upwd='" + pwd + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(StrSql, constring);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                foreach (DataRow item in dt.Rows)
                {
                    Users UersModel = new Users();
                    UersModel.Uid = Convert.ToInt32(item["Uid"]);
                    UersModel.Uname = item["Uname"].ToString();
                    UersModel.Rolename = item["Rolename"].ToString();
                    UersModel.Roleid =Convert.ToInt32( item["Roleid"]);
                    UersModel.BMid = Convert.ToInt32(item["BMid"]);
                    UersModel.Eid = Convert.ToInt32(item["Eid"]);
                    UersModel.Iid = Convert.ToInt32(item["Iid"]);
                    UersModel.KeyCode = Convert.ToInt32(item["KeyCode"]);
                    UersModel.Upwd = item["Upwd"].ToString();
                    UersModel.UEmail = item["UEmail"].ToString();
                    UersModel.Uphone = item["Uphone"].ToString();
                    list.Add(UersModel);
                }
                return list;
            }
            catch (Exception ee)
            {
                string ExcepMessage = ee.Message;
                throw;
            }
            finally { 
            
            }
        }
    }
}
